// 结果输出文件夹
// #define OUTPUT_DIR "TestData/Post/NH5Export/"

#include "gtest/gtest.h"
#include <filesystem>

#include "DBManager/Database/DatabaseFactory.h"
#include "DBManager/Service/DBServiceFactory.h"

using namespace SG::DBManager;

/// @brief 数据库服务工厂
std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY = nullptr;

class H5DBEnvironment : public testing::Environment
{
  public:
    DataBaseFactory* m_dbFactory = nullptr;

    virtual void SetUp ()
    {
        // 数据库工厂
        m_dbFactory = new DataBaseFactory ();
        // 数据库
        IDataBase* db = m_dbFactory->GetDataBase (DataBaseFactory::HDF5, ".", "NH5ExportUnitTest.db");
        // 根据数据库创建Service管理器
        DB_SERVICEFACTORY = std::make_shared<DBServiceFactory> (db);
    }
    virtual void TearDown ()
    {
        // 释放数据库资源
        DB_SERVICEFACTORY.reset ();
        delete m_dbFactory;
    }
};

int main (int argc, char* argv[])
{
    testing::AddGlobalTestEnvironment (new H5DBEnvironment ());

    // namespace fs      = std::filesystem;
    // fs::path dir_path = OUTPUT_DIR;
    // if (!fs::exists (dir_path))
    //     fs::create_directories (dir_path);

    testing::InitGoogleTest (&argc, argv);
    return RUN_ALL_TESTS ();
}